const { READ_FILE } = require('../ipcTypes');
const { ipcRenderer } = window.electron;
let readFileActionId = 0;
function readFile(path, encode) {
  const readFileAction = `readFileActionId_${readFileActionId++}`;
  ipcRenderer.send(READ_FILE, path, encode, readFileAction);
  return new Promise((resolve, reject) => {
    ipcRenderer.once(readFileAction, (event, isSuccess, data) => {
      if (isSuccess) {
        resolve(data);
      } else {
        reject(data);
      }
    })
  });
}


module.exports = readFile;
